home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************/
- /* */
- /* TurboCAD for Windows */
- /* Copyright (c) 1993 - 2001 */
- /* International Microcomputer Software, Inc. */
- /* (IMSI) */
- /* All rights reserved. */
- /* */
- /******************************************************************/
-
- // ViewWnd.cpp : implementation file
- // This class perform preview of External object.
-
- // ----------- CreatePreview() function -----------------
- // Create new drawing that we use to display ExternalObject
- // Currently there is not possibility to create new drawing with TurboCAD's SDK in way
- // that this drawing was invisible for user
- // So we have to use TurboCAD's engine functions to create new drawing that we use to display external objects
- // This function is called one time when tool is started to setup preview drawing
- // ----------- DoPreview() function ---------------------
- // Display External object selected in Objects list in Preview window
-
-
-
-
- #include "stdafx.h"
- #include "InsSmObj.h"
- #include "ViewWnd.h"
- #include "SdiDialog.h"
-
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CPreviewWnd CViewWnd
- const long GF_COSMETIC = 128;
- const long GF_ALL = 0;
-
- CPreviewWnd::CPreviewWnd()
- {
- m_FirstStart = TRUE;
- m_pIApp = NULL;
- m_pDrawCol = NULL;
- m_pPreviewDrawing = NULL;
- m_pPreviewGrs = NULL;
- m_pPreviewView = NULL;
- m_pViewsCol = NULL;
- m_pPreviewGraphic = NULL;
-
- }
-
- CPreviewWnd::~CPreviewWnd()
- {
- }
-
-
- BEGIN_MESSAGE_MAP(CPreviewWnd, CWnd)
- //{{AFX_MSG_MAP(CPreviewWnd)
- ON_WM_PAINT()
- ON_WM_ERASEBKGND()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
-
- /////////////////////////////////////////////////////////////////////////////
- // CPreviewWnd message handlers
-
- void CPreviewWnd::OnPaint()
- {
- CPaintDC dc(this); // device context for painting
-
- if (m_pPreviewView == NULL)
- return;
-
- // Force redraw of view window
- try
- {
- HRESULT hRes = m_pPreviewView->Refresh();
- CHECK_HRESULT(hRes)
-
-
- }
- catch (...)
- {
- TRACE_EXCEPTION("CPreviewWnd::OnPaint")
- }
-
- }
-
- BOOL CPreviewWnd::OnEraseBkgnd(CDC* pDC)
- {
- CRect rect;
- GetClientRect(rect);
- pDC->FillSolidRect(rect, ::GetSysColor(COLOR_WINDOW));
- return TRUE;
- }
-
-
-
- void CPreviewWnd::CreatePreview() //create a preview drawing
- {
- HRESULT hRes;
- COleVariant varType((const long)imsiPolyline);
- COleVariant varOptional(varMissing);
-
- try
- {
- // protect from run this function several times
- // we create preview drawing one time just after tool is runned
- // after that we call DoPreview() function to display External Object (selected in the Objects list)
- // in Preview window (IDC_PREVIEW)
- if (m_FirstStart == TRUE)
- {
- ClearAll();
- HMODULE hDBAPI = NULL;
- hDBAPI = GetModuleHandle(DBAPI14);
- if (hDBAPI == NULL)
- {
- hDBAPI = GetModuleHandle(DBAPI12);
- if (hDBAPI == NULL)
- {
- hDBAPI = GetModuleHandle(DBAPI11);
- if (hDBAPI == NULL)
- {
- hDBAPI = GetModuleHandle(DBAPI10);
- if (hDBAPI == NULL)
- {
- hDBAPI = GetModuleHandle(DBAPI90);
- if (hDBAPI == NULL)
- {
- hDBAPI = GetModuleHandle(DBAPI80);
-
- if (hDBAPI == NULL)
- {
- hDBAPI = GetModuleHandle(DBAPI70);
-
- if (hDBAPI == NULL)
- {
- hDBAPI = GetModuleHandle(DBAPI60);
- }
- }
- }
- }
- }
- }
- }
- if (hDBAPI == NULL)
- return;
- else
- m_pfGetApp = (APPGETCURRENTAPP)GetProcAddress(hDBAPI, _T("AppGetCurrentApp"));
- if (m_pfGetApp == NULL)
- return;
-
-
- m_lApp = (*m_pfGetApp)();
- if (m_lApp == 0)
- return;
-
-
- m_pfAppDwgNew = (APPDRAWINGNEWEX)GetProcAddress(hDBAPI, _T("AppDrawingNewEx"));
- if (m_pfAppDwgNew == NULL)
- {
- AfxMessageBox("m_pfAppDwgNew == NULL");//# Non-localizable string#
-
- }
-
- BOOL i;
- i = TRUE;
- // Create a new drawing with TurboCAD's engine call that we use for preview of External objects
- m_lDwg = (*m_pfAppDwgNew)(m_lApp, i, NULL, NULL, true);
-
- COleVariant varItem = (0L);
- long nDrawings = 0;
-
-
- hRes = ((CSdiDialog*)GetParent())->m_pRegMets->get_Application(&m_pIApp);
- CHECK_HRESULT(hRes)
-
- hRes = m_pIApp->get_Drawings(&m_pDrawCol);
- CHECK_HRESULT(hRes)
-
- hRes = m_pDrawCol->get_Count(&nDrawings);
- CHECK_HRESULT(hRes)
-
- varItem = nDrawings - 1L;
-
- hRes = m_pDrawCol->get_Item(&varItem, &m_pPreviewDrawing);
-
- hRes = m_pPreviewDrawing->get_Views(&m_pViewsCol);
-
- // long nViews = 0;
-
- HWND hWnd = ::GetDlgItem(GetParent()->m_hWnd, IDC_PREVIEW);
- COleVariant varHwnd((long)hWnd);
-
- // Create new view to just created drawing and assign to this view HWND of IDC_PREVIEW (Preview window)
- hRes = m_pViewsCol->Add(&varHwnd, &varOptional, &m_pPreviewView );
- CHECK_HRESULT(hRes)
-
-
-
- // SetUp just created view
- hRes = m_pPreviewView->put_Update(FALSE);
- CHECK_HRESULT(hRes)
-
-
- hRes = m_pPreviewView->put_MappingMode(MM_TEXT);
- CHECK_HRESULT(hRes)
-
- hRes = m_pPreviewView->put_FixedAspectRatio(TRUE);
- CHECK_HRESULT(hRes)
-
- hRes = m_pPreviewView->put_Margins(FALSE);
- CHECK_HRESULT(hRes)
-
- CPreviewWnd *pPreview = (CPreviewWnd *) (((CSdiDialog*)GetParent())->GetDlgItem(IDC_PREVIEW));
-
-
- CRect rcBounds;
- pPreview->GetClientRect(&rcBounds);
-
- hRes = m_pPreviewView->put_ScreenLeft(rcBounds.left);
- CHECK_HRESULT(hRes)
-
- hRes = m_pPreviewView->put_ScreenTop(rcBounds.top);
- CHECK_HRESULT(hRes)
-
- hRes = m_pPreviewView->put_ScreenWidth(rcBounds.Width());
- CHECK_HRESULT(hRes)
-
- hRes = m_pPreviewView->put_ScreenHeight(rcBounds.Height());
- CHECK_HRESULT(hRes)
-
- hRes = m_pPreviewView->ZoomToExtents();
- CHECK_HRESULT(hRes)
-
- m_FirstStart = FALSE;
- }
- }
- catch (...)
- {
- TRACE_EXCEPTION("CPreviewWnd::CreatePreview")
- }
- }
-
-
-
- void CPreviewWnd::Clear()
- {
- if (m_pPreviewGraphic != NULL)
- {
- m_pPreviewGraphic->put_Deleted(TRUE);
- m_pPreviewGraphic->Release();
- m_pPreviewGraphic = NULL;
- }
-
- Invalidate();
- }
-
- void CPreviewWnd::ClearAll()
- {
- if (m_pPreviewGraphic != NULL)
- {
- m_pPreviewGraphic->put_Deleted(TRUE);
- m_pPreviewGraphic->Release();
- m_pPreviewGraphic = NULL;
- }
- if (m_pPreviewGrs != NULL)
- {
- m_pPreviewGrs->Release();
- m_pPreviewGrs = NULL;
-
- }
- if (m_pPreviewView != NULL)
- {
- m_pPreviewView->Release();
- m_pPreviewView = NULL;
-
- }
- if (m_pViewsCol != NULL)
- {
- m_pViewsCol->Release();
- m_pViewsCol = NULL;
-
- }
- if (m_pPreviewDrawing != NULL)
- {
- COleVariant varOptional(varMissing);
- m_pPreviewDrawing->Close(varOptional, varOptional, varOptional);
- m_pPreviewDrawing->Release();
- m_pPreviewDrawing = NULL;
-
- }
-
- if (m_pDrawCol != NULL)
- {
- m_pDrawCol->Release();
- m_pDrawCol = NULL;
-
- }
-
- if (m_pIApp != NULL)
- {
- m_pIApp->Release();
- m_pIApp = NULL;
-
- }
- m_FirstStart = TRUE;
-
- }
-
- void CPreviewWnd::DoPreview()
- {
- HRESULT hRes;
- COleVariant varType((const long)imsiGroup);
- COleVariant varOptional(varMissing);
- IDrawing *pIDwg = NULL;
- IApplication *pIApp = NULL;
- Properties *pProps = NULL;
- Property *pProp = NULL;
- Properties *pProps1 = NULL;
- Property *pProp1 = NULL;
- COleVariant varVal;//(1L);
- COleVariant flags = (const long)GF_ALL;
- try
- {
- // set PreviewDrawing Mode (Model Space or Paper Space) the same like active drawing
- // imsiModelSpace = 1, imsiPaperSpace = 0
- hRes = ((CSdiDialog*)GetParent())->m_pRegMets->get_Application(&pIApp);
- CHECK_HRESULT(hRes)
-
- hRes = pIApp->get_ActiveDrawing(&pIDwg);
- CHECK_HRESULT(hRes)
- //
- CString cstrName("TileMode");//# Non-localizable string#
- BSTR bstrName = cstrName.AllocSysString();
-
- VARIANT varItem1;
- ::VariantInit(&varItem1);
- varItem1.vt = VT_BSTR;
- varItem1.bstrVal = bstrName;
-
- // get properties of current active drawing
- hRes = pIDwg->get_Properties(&pProps);
- CHECK_HRESULT(hRes)
-
- hRes = pProps->get_Item(&varItem1, &pProp);
- CHECK_HRESULT(hRes)
-
- hRes = pProp->get_Value(NULL, varVal);
- CHECK_HRESULT(hRes)
-
- // get properties of Preview drawing
- hRes = m_pPreviewDrawing->get_Properties(&pProps1);
- CHECK_HRESULT(hRes)
-
- hRes = pProps1->get_Item(&varItem1, &pProp1);
- CHECK_HRESULT(hRes)
-
- if (varVal.lVal == imsiModelSpace)
- {
- hRes = pProp1->put_Value(NULL, varVal);
- CHECK_HRESULT(hRes)
- }
- else
- {
- hRes = pProp1->put_Value(NULL, varVal);
- CHECK_HRESULT(hRes)
- }
- Invalidate();
-
- ::VariantClear(&varItem1);
-
- CExternalObjectsList *pList = (CExternalObjectsList *) (GetParent()->GetDlgItem(IDC_EXTOBJECTSLIST));
-
- int index = pList->GetCurSel();
-
- pList->GetText(index, m_cstrSelected);
-
- COleVariant varRegen(m_cstrSelected);
- hRes = m_pPreviewDrawing->get_Graphics(&m_pPreviewGrs);
- CHECK_HRESULT(hRes)
-
- hRes = m_pPreviewGrs->Clear(&flags);
-
- hRes = m_pPreviewGrs->Add(&varRegen,
- &varRegen,
- &varOptional,
- &varOptional,
- &varOptional,
- &varOptional,
- &m_pPreviewGraphic);
-
- CHECK_HRESULT(hRes)
-
- hRes = m_pPreviewView->ZoomToExtents();
- CHECK_HRESULT(hRes)
- }
- catch (...)
- {
- TRACE_EXCEPTION("CPreviewWnd::DoPreview")
- }
-
- if (pProp1 != NULL)
- pProp1->Release();
-
- if (pProps1 != NULL)
- pProps1->Release();
-
- if (pProp != NULL)
- pProp->Release();
-
- if (pProps != NULL)
- pProps->Release();
-
- if (pIDwg != NULL)
- pIDwg->Release();
- }
-